#ifndef _SNIFFER_
#define _SNIFFER_

#include <pcap.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netinet/if_ether.h>
#include <net/ethernet.h>
#include <netinet/ether.h>
#include <netinet/ip.h>
#include <string.h>
#include <ctype.h>
#include <unistd.h>
#include <boost/thread/thread.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/condition.hpp>
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include "SwafStructs.h"
#include "ConfigFile.h"
#include "SharedQueue.h"

using namespace std;


#define IP_HEADER_OFFSET 14
#define FLTRSZ 120
#define MAXHOSTSZ 256
#define ADDR_STRSZ 16


//#define DEBUG_SNIFFER
#define MAX_SNIFFER_RESTARTS 10
#define NEED_TO_RESTART_VAL 10

class Sniffer
{
private:
	string _ws_ip; // the web server ip adress
	string _ws_port; // the web server port
	string _interface; // the sniffed interface
    string _pcapFilter; // the sniffer filter
	pcap_t *_pckCapDesc; // pointer to the packet capture descriptor
	SharedQueue<struct RAWIPDATA> *_snifferQ; // pointer to the sniffer queue
	int _numSniffedPackets; // number of the sniffed packets
	int _errorPacketRead; // the number of errors while reading a packet
	int _snifferRestarts; // the number of times sniffer had to be restarted

public:
	Sniffer(SharedQueue<struct RAWIPDATA>*);
	virtual ~Sniffer();
	void config();
	void init();
	void runSniffer();
	void handlePacket(const struct pcap_pkthdr*,const u_char*);
	void restartSnifferRun();
};

#endif//_SNIFFER_
